package org.ns.summer.aop;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

public class CglibProxyUtils {


    public static <T> T proxy(Class<?> beanType, MethodInterceptor methodInterceptor) {
        Enhancer enhancer = new Enhancer();
        enhancer.setCallback(methodInterceptor);

        if (beanType.isInterface()) {
            enhancer.setInterfaces(new Class[]{beanType, SummerProxy.class});
        } else {
            enhancer.setSuperclass(beanType);
            enhancer.setInterfaces(new Class[]{SummerProxy.class});
        }
        return (T)enhancer.create();
    }



    public static interface SummerProxy {
        public Class getTargetClass();
    }
}
